package com.ibeeking.found.open.api.feign.fallback;

import com.ibeeking.found.open.api.common.dto.GoodsInfoDTO;
import com.ibeeking.found.open.api.common.dto.GoodsListDTO;
import com.ibeeking.found.open.api.common.query.GoodsIdQuery;
import com.ibeeking.found.open.api.common.query.GoodsListQuery;
import com.ibeeking.found.open.api.feign.GoodsFeignClient;
import com.ibeeking.nematos.utils.base.page.Page;
import com.ibeeking.nematos.utils.result.ResponseCodeEnum;
import com.ibeeking.nematos.utils.result.ResponseResult;
import feign.hystrix.FallbackFactory;
import org.springframework.stereotype.Component;


/**
 * 降级工场
 *
 * @Author ibeeking
 * @date 2019/1/18
 */
@Component
public class GoodsFeignFallbackFactory implements FallbackFactory<GoodsFeignClient> {
    @Override
    public GoodsFeignClient create(Throwable throwable) {
        return new GoodsFeignClient() {

            @Override
            public ResponseResult<Page<GoodsListDTO>> apiGoodsPageList(GoodsListQuery query) {
                return ResponseResult.fail(ResponseCodeEnum.SYSTEM_ERROR.getCode(), "进入降级工厂，查询分页商品失败。", new Page<>());
            }

            @Override
            public ResponseResult<GoodsInfoDTO> apiGoodsInfo(Long goodsId) {
                return ResponseResult.fail(ResponseCodeEnum.SYSTEM_ERROR.getCode(), "进入降级工厂，查询分页商品失败。", null);
            }

            @Override
            public ResponseResult<Long> oneOnShelfLargeSizeGoodsId(GoodsIdQuery query) {
                return ResponseResult.fail(ResponseCodeEnum.SYSTEM_ERROR.getCode(), "进入降级工厂，查询商品ID失败。", null);
            }
        };
    }
}
